<?php
class User extends MY_Model {

    var $table_name = 'user';
	var $primary_key = 'id';

    function authentication($username,$password)
    {
        $query = $this->db->query("SELECT * FROM user WHERE username=? AND password = ?",array($username,md5($password)));
        if ($query->num_rows() > 0)
		{
		   return(array_merge($query->row_array(),array('logged_in'=>true)));
		} 
		else return false;
    }
	protected function filterData(&$data){
		foreach($data as $key=>$row){
			if (!$this->db->field_exists($key, $this->table_name)||empty($row))
			{
				unset($data[$key]);
			}
			elseif($key == 'password')
				$data[$key] = md5($data[$key]);
		}
    }

}